package cn.wizzer.app.user.modules.models;

import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.integration.json4excel.annotation.J4EIgnore;
import org.nutz.json.JsonField;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Set;

/**
 * 用户管理 create by herexu 20191115
 */
//Nutz暂不支持全文索引，暂时不加，当出现问题时再加
@Data
@Table("user")
@TableIndexes({@Index(name = "INDEX_USER_USERNAME", fields = {"userName"}, unique = true),
        @Index(name = "INDEX_CT_AT", fields = {"ctAt"}, unique = false)})
@TableMeta("{mysql-charset:'utf8mb4'}")
public class User extends BaseModel implements Serializable {

    @Column
    @Name
    @Comment("ID")
    @J4EIgnore
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(uu32 = true)
    private String id;

    @Column
    @Comment("昵称")
    @ColDefine(type = ColType.VARCHAR, width = 20)
    private String nickName;

    @Column
    @Comment("头像")
    @JsonField
    @ColDefine(type = ColType.VARCHAR, width = 128)
    private String headPicture;

    @Column
    @Comment("签名")
    @JsonField
    @ColDefine(type = ColType.VARCHAR, width = 256)
    private String sign;

    @Column
    @Comment("手机号码")
    @ColDefine(type = ColType.VARCHAR, width = 11)
    private String phone;

    @Column
    @Comment("密码")
    @ColDefine(type = ColType.VARCHAR, width = 256)
    private String password;


    @Column
    @Comment("随机盐")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String salt;

    @Column("is_online")
    @Comment("是否在线0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean isOnline;

    @Column
    @Comment("是否禁用0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean disabled;

    @Column
    @Comment("是否主播0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean anchor;

    @Column("anchor_heat")
    @Comment("是否主播0否1是")
    @ColDefine(type = ColType.INT, width=4)
    private Integer anchorHeat;

    @Column("room_manager")
    @Default("0")
    @Comment("房管0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean roomManager;

    @Column("session_disabled")
    @Comment("禁言0否1是")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean sessionDisabled;

    @Column("invite_code")
    @Comment("邀请码")
    @ColDefine(type = ColType.VARCHAR, width = 8)
    private String inviteCode;

    @Column("inviter")
    @Comment("邀请人")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String inviter;

    private Set<String> manageRoom;

    private String channelId;

    private String roomId;

    /**
     * 规则hv+手机号后四位+邀请码后两位。钻石划转使用
     */
    @Column
    @Comment("用户名。规则hv+手机号后+邀请码后两位。钻石划转使用")
    @ColDefine(type = ColType.VARCHAR, width = 8)
    private String userName;

    /**
     * 是否可收款，默认都是false，后端有开关控制，划转时做的判断
     */
    @Column("is_collect")
    @Comment("是否可收款0否1是")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean isCollect;
    /**
     * 是否可进入游戏大厅
     */
    @Column("playable")
    @Comment("是否可以进入游戏大厅")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean playable;
    /**
     * 是否为代理人
     */
    @Column
    @Comment("是否为代理人")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean agent;
    /**
     * 是否已认证
     */
    @Column
    @Comment("是否已认证")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean certified;
    /**
     * 是否为客服
     */
    @Column
    @Comment("客服")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean attendant;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    @Column
    @Comment("最后登录")
    private Long lastLoginAt;

    @Column
    @Comment("登录次数")
    @Default("0")
    private Long loginTimes;

    @Column
    @Comment("登录时长(h)")
    @ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
    @Default("0")
    private BigDecimal loginDuration;

    @Column
    @Comment("登录ip")
    @ColDefine(type = ColType.VARCHAR, width = 255)
    private String ip;

    @Column("is_rebate")
    @Comment("是否返利")
    @Default("0")
    @ColDefine(type = ColType.BOOLEAN)
    private boolean isRebate;

}
